#include <iostream>
#include <regex>
#include <string>
#include <vector>

void ReplaceString(std::string &s, const std::string &src, const std::string &dst)
{
    std::string::size_type pos = 0;
    std::string::size_type srcLen = src.size();
    std::string::size_type dstLen = dst.size();
    while ((pos = s.find(src, pos)) != std::string::npos)
    {
        s.replace(pos, srcLen, dst);
        pos += dstLen;
    }
}

int main(int argc, char **argv)
{
    std::string s = "1,2,3,4,1,2";
    std::cout << "Original string:" << s << std::endl;
    ReplaceString(s, "4", "44");
    std::cout << "Relace '4' with '44':" << s << std::endl;
    ReplaceString(s, "2", "22");
    std::cout << "Relace '2' with '22':" << s << std::endl;
    return 0;
}

//Original string:1,2,3,4,1,2
//Relace '4' with '44':1,2,3,44,1,2
//Relace '2' with '22':1,22,3,44,1,22